
//
//  ThirdLoginShareView.m
//  StarBuyer
//
//  Created by 钟游 on 2019/8/25.
//  Copyright © 2019年 bigbo. All rights reserved.
//

#import "ThirdLoginShareView.h"

@interface ThirdLoginShareView()
{
    NSString * messType;
    NSArray * infoArray;
    
}
@end
@implementation ThirdLoginShareView

-(instancetype)initWithFrame:(CGRect)frame andInfoArray:(NSArray*)array andType:(NSString*)type;{
    if (self=[super initWithFrame:frame]) {
        messType = [type mutableCopy];
        infoArray=[array mutableCopy];
        self.backgroundColor=[UIColor clearColor];
        [self createUI];
    }
    return self;
}
#pragma mark ---
-(void)clickSender:(UIButton*)sender{
    NSInteger tag = sender.tag-100;
    NSString * title = infoArray[tag][@"title"];
    if (_delegate && [_delegate respondsToSelector:@selector(clickBtnWithTitle:)]) {
        [_delegate clickBtnWithTitle:title];
    }
}
#pragma mark -- UI
-(void)createUI{
    UILabel * titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 10, KscreenWidth, 20)];
    titleLabel.font=[UIFont systemFontOfSize:15];
    titleLabel.textAlignment = NSTextAlignmentCenter;
    if ([messType isEqualToString:@"登陆"]) {
        titleLabel.text =[NSString stringWithFormat:@"----------%@----------",@"第三方登录"];
    }else{
        titleLabel.text =[NSString stringWithFormat:@"----------%@----------",@"第三方分享"];
    }
    titleLabel.textColor =UIColorFromRGB(0xFFFFFF);
    [self addSubview:titleLabel];
    
    for (int i = 0; i<infoArray.count; i++) {
        NSDictionary * dict =infoArray[i];
        UIButton * btn =[UIButton buttonWithType:UIButtonTypeCustom];
        btn.frame = CGRectMake( (KscreenWidth-(infoArray.count*2-1)*41)/2+i*82, CGRectGetMaxY(titleLabel.frame)+19, 41, 41);
        btn.tag =100+i;
        btn.backgroundColor=[UIColor clearColor];
        [btn setImage:[UIImage imageNamed:dict[@"image"]] forState:UIControlStateNormal];
        [btn addTarget:self action:@selector(clickSender:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:btn];
    }
        
        }
@end
